package com.wei.czz.framework.rabbitMQ.listener;

import com.wei.czz.common.enums.common.exportTask.TaskTypeEnum;
import com.wei.czz.common.enums.rabbitMQ.MqEnum;
import com.wei.czz.framework.blog.helper.BlogCommentHelper;
import com.wei.czz.framework.common.service.ExportTaskService;
import com.wei.czz.framework.blog.dao.BlogCommentDao;
import com.wei.czz.framework.rabbitMQ.message.task.ExportTaskMessage;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2022-03-23 21:10:02
 * className: ExportQueueListener 系统任务导出消息队列监听类
 * version: 1.0
 * description:
 */
@Component
@AllArgsConstructor
public class ExportQueueListener {

    private static final Logger log = LoggerFactory.getLogger(ExportQueueListener.class);

    private final BlogCommentDao blogCommentDao;

    private final BlogCommentHelper blogCommentHelper;

    private final ExportTaskService exportTaskService;

    /**
     * 系统文件导出任务消息监听方法
     * 根据系统任务导出消息对象，生成导出数据，并数据写入响应文件中
     * @param exportTaskMessage 系统任务导出消息对象
     */
    @RabbitListener(queues = {MqEnum.Queue.EXPORT_TASK})
    public void exportTaskMessage(ExportTaskMessage exportTaskMessage) {
        log.info("开始异步处理系统文件导出任务业务。{}", exportTaskMessage);

        if (TaskTypeEnum.COMMENT_LIST_EXPORT.getValue().equals(exportTaskMessage.getTaskType())) {
            /*
               导出博客评论
             */
            blogCommentHelper.blogCommentWriteFile(exportTaskMessage);

        } else {
            log.error("导出任务类型未知，请务必及时处理");
        }
        log.info("异步处理系统文件导出任务业务结束");
    }

}

